package net.zjitc.controller;

import net.zjitc.pojo.AdminUser;
import net.zjitc.service.AdminUserService;
import net.zjitc.service.impl.AdminUserServiceImpl;
import net.zjitc.utils.dispacher.URLMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Created by lenovo on 2017/11/26.
 */
public class AdminUserCon {
    AdminUserService service=new AdminUserServiceImpl();
    //用户登录
    @URLMapping(url = "/adminuserLogin")
    public String login(HttpServletRequest request, HttpServletResponse response){
        String username=request.getParameter("username");
        String password=request.getParameter("password");
        AdminUser user=service.findByCondition(username,password);
        HttpSession session=request.getSession();
        if (user!=null){
            session.setAttribute("admin",user);
            return "Redirect:"+request.getContextPath()+"/admin/home.jsp";
        }else {
            return "Redirect:"+request.getContextPath()+"/admin/login.jsp";
        }
    }
    //退出登录
    @URLMapping(url = "/loginOut")
    public String loginOut(HttpServletRequest request, HttpServletResponse response){
        HttpSession session=request.getSession();
        session.removeAttribute("admin");
        return "Redirect:"+request.getContextPath()+"/admin/top.jsp";
    }
}
